package com.ruoyi.project.manhua.type.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.manhua.type.domain.MhType;
import com.ruoyi.project.manhua.type.service.IMhTypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 漫画类型Controller
 * 
 * @author yuan
 * @date 2021-01-12
 */
@Controller
@RequestMapping("/manhua/type")
public class MhTypeController extends BaseController
{
    private String prefix = "manhua/type";

    @Autowired
    private IMhTypeService mhTypeService;

    @RequiresPermissions("manhua:type:view")
    @GetMapping()
    public String type()
    {
        System.out.println("ssss");
        return prefix + "/type";
    }

    /**
     * 查询漫画类型列表
     */
    @RequiresPermissions("manhua:type:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MhType mhType)
    {
        startPage();
        List<MhType> list = mhTypeService.selectMhTypeList(mhType);
        return getDataTable(list);
    }

    /**
     * 导出漫画类型列表
     */
    @RequiresPermissions("manhua:type:export")
    @Log(title = "漫画类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MhType mhType)
    {
        List<MhType> list = mhTypeService.selectMhTypeList(mhType);
        ExcelUtil<MhType> util = new ExcelUtil<MhType>(MhType.class);
        return util.exportExcel(list, "type");
    }

    /**
     * 新增漫画类型
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存漫画类型
     */
    @RequiresPermissions("manhua:type:add")
    @Log(title = "漫画类型", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MhType mhType)
    {
        return toAjax(mhTypeService.insertMhType(mhType));
    }

    /**
     * 修改漫画类型
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        MhType mhType = mhTypeService.selectMhTypeById(id);
        mmap.put("mhType", mhType);
        return prefix + "/edit";
    }

    /**
     * 修改保存漫画类型
     */
    @RequiresPermissions("manhua:type:edit")
    @Log(title = "漫画类型", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MhType mhType)
    {
        return toAjax(mhTypeService.updateMhType(mhType));
    }

    /**
     * 删除漫画类型
     */
    @RequiresPermissions("manhua:type:remove")
    @Log(title = "漫画类型", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(mhTypeService.deleteMhTypeByIds(ids));
    }
}
